package com.googlecode.jnarwhal.input;

import org.lwjgl.input.Mouse;

import com.googlecode.jnarwhal.event.EventManager;


/**
 * The InputManager is used to poll for user input (Mouse or Keyboard).
 * @author Chris
 *
 */
public class InputManager {

	/**
	 * Initialize the InputManager
	 */
	public static void init() {
		
	}
	
	/**
	 * poll for new mouse and keyboard input
	 */
	public static void pollInput() {
		//poll for mouse input
		while(Mouse.next()) {
			int x = Mouse.getEventX();
			int y = Mouse.getEventY();
			int dx = Mouse.getEventDX();
			int dy = Mouse.getEventDY();
			int button = Mouse.getEventButton();
			int mousewheel = Mouse.getEventDWheel();
			boolean buttonstate = Mouse.getEventButtonState();
			//MouseMoveEvent
			if(dx != 0 || dy != 0) {
				EventManager.callEvent(new MouseMoveEvent(x,y,dx,dy));
			}
		    //Mouse button was pressed
			if (button >= 0) {
				if (buttonstate) {
					EventManager.callEvent(new MouseDownEvent(x,y,button));
				} else {
					EventManager.callEvent(new MouseUpEvent(x,y,button));
				}
			}
		}
	}
}
